<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>编辑借支单</title>
	<#include "/common/resource.ftl">
	<script type="text/javascript">
        var getStepUsers = function() {
            <#if !((params.id)??)>
            $.ajaxRequest({
                url: '${params.contextPath}/web/workflowStep/getNextStepUsers',
                data: {workflowDefineId: "${params.defineId!}", stepNum: 0},
                success: function (data) {
                    if (!data.success) {
                        $.message(data.message);
                        return;
                    }
                    var list = data.data, stepName = "", options = "";
                    for (var i = 0; i < list.length; i ++) {
                        options += '<option value="{userId}">--{userName}--</option>'.format(list[i]);
                        stepName = list[i].stepName;
                    }
                    $('[name="nextStepName"]').val(stepName);
                    $('[name="nextStepUserId"]').append(options);
                }
            });
            </#if>
        };
		$(function () {
			<#if (params.id)??>
				$.ajaxRequest({
					url: '${params.contextPath}/web/debitNote/query.json',
					data: {id: "${params.id}"},
					success: function (data) {
						if (!data.success) {
							$.message(data.message);
							return;
						}
						var record = data.data;
						for (var key in record) {
							$("[name='" + key + "']").val(record[key]);
						}

                        $("[name='happenDate']").val(record.happenDateStr);
                        $("[name='repayDate']").val(record.repayDateStr);
					}
				});
            <#else>
                getStepUsers();
			</#if>
            $(".ajax-form2").unbind().submit(function () {
                try {
                    var form = $(this);
                    if (!form.valid()) {
                        $.message("验证不通过，无法提交表单");
                        return false;
                    }

                    form.formSubmit({
                        callBack:function (data) {
                            <#if !((params.id)??)>
                            history.go(-1);
                            </#if>
                        }
                    });
                } catch (e) {
                    console.log("表单提交错误：" + e);
                }
                return false;
            });
		});
	</script>
</head>
<body>
<div class="ui-form" style="padding:20px;">
    <div class="layui-card">
        <div class="layui-card-header">借支单</div>
        <div class="layui-card-body">
            <form class="layui-form ajax-form2" action="${params.contextPath}/web/debitNote/<#if (params.id)??>modify<#else>save</#if>.json" method="post">
                <input type="hidden" name="id" value="${params.id!}" />
                <input type="hidden" name="workflowDefineId" value="${params.defineId!}" />
                <fieldset class="layui-elem-field">
                    <legend style="color:#FF5722;">申请单信息</legend>
                    <div class="layui-field-box">
                        <div class="layui-form-item">
                            <label class="layui-form-label">申请日期<span class="ui-request">*</span></label>
                            <div class="layui-input-block">
                                <input type="text" name="happenDate" placeholder="请输入申请日期" class="layui-input ui-date {required:true}" readonly/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">还款日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="repayDate" placeholder="请输入还款日期" class="layui-input ui-date" readonly/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">支付方式<span class="ui-request">*</span></label>
                            <div class="layui-input-block">
                                <select name="payType" class="layui-input {required:true}">
                                    <option value="">请选择</option>
                                    <option value="1">现金</option>
                                    <option value="2">转账</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">部门<span class="ui-request">*</span></label>
                            <div class="layui-input-block">
                                <input type="text" name="deptName" placeholder="请输入部门" class="layui-input {required:true}"/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">借支事由<span class="ui-request">*</span></label>
                            <div class="layui-input-block">
                                <textarea name="content" placeholder="请输入借支事由" class="layui-textarea {required:true}"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">借支金额<span class="ui-request">*</span></label>
                            <div class="layui-input-block">
                                <input type="text" name="amount" placeholder="请输入借支金额" class="layui-input {required:true}"/>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">备注</label>
                            <div class="layui-input-block">
                                <textarea name="remark" placeholder="请输入备注" class="layui-textarea"></textarea>
                            </div>
                        </div>
                    </div>
                </fieldset>

                <#if !((params.id)??)>
                    <fieldset class="layui-elem-field">
                        <legend style="color:#FF5722">流程审批信息</legend>
                        <div class="layui-field-box">
                            <div class="layui-form-item">
                                <label class="layui-form-label">下节点名称</label>
                                <div class="layui-input-block">
                                    <input type="text" name="nextStepName" class="layui-input" readonly/>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">选择处理人<span class="ui-request">*</span></label>
                                <div class="layui-input-block">
                                    <select name="nextStepUserId" class="layui-input {required:true}">
                                        <option value="">--请选择下个节点处理人--</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                </#if>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input type="submit" value="提交申请" class="layui-btn" />
                    </div>
                </div>
            </form>
        </div>
	</div>
</div>
</body>

</html>
